
const http = require('http');
const url = require('url');

const server = http.createServer((req, res) => {
    let urlStr = req.url;
    let urlObj = url.parse(urlStr, true);// true 变成对象

    console.log('urlObj--------', urlObj);

    switch (urlObj.pathname) {
        case '/api/data':
            // res.write('getData("hello")') //  
            res.write(`${urlObj.query.cb}('hello')`) // callback
            break;
        default:
            res.write('page noe fond');
    };

    res.end()
});

server.listen(8080)

